from flask import jsonify, request, send_from_directory
from flask_socketio import SocketIO
import os
import random
import string
import time
from datetime import datetime

# app = Flask(__name__)
# CORS(app)
from api.share import app,shared_vars

# Ensure the upload directory exists
UPLOAD_FOLDER = 'models_uploaded'
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER

# Import API blueprints
from api.auth import auth_bp
from api.jobs import jobs_bp
from api.worker_nodes import worker_nodes_bp
from api.users import users_bp

# Register blueprints
app.register_blueprint(auth_bp, url_prefix='/api/auth')
app.register_blueprint(jobs_bp, url_prefix='/api/jobs')
app.register_blueprint(worker_nodes_bp, url_prefix='/api/worker-nodes')
app.register_blueprint(users_bp, url_prefix='/api/users')

from api.worker_websocket import WorkerWebSocketNamespace
app.config['SECRET_KEY'] = 'your_secret_key'
socketio = SocketIO(app, cors_allowed_origins='*')
# Register namespace to /api/websocket
socketio.on_namespace(WorkerWebSocketNamespace('/api/worker-ws'))
shared_vars['socketio'] = socketio

@app.route('/')
def index():
    return jsonify({'message': 'Welcome to ACE MVP API'})

if __name__ == '__main__':
    # app.run(debug=True, host='0.0.0.0', port=7001)
    socketio.run(app,debug=True, host='0.0.0.0',port=7001, allow_unsafe_werkzeug=True)
